<?php
require_once "wp-config.php";
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME);
mysql_query("SET NAMES utf8"); //connect in decode utf8
//$table_prefix
$img = array();
for ($i=1;$i<=5;$i++) {
	$img[$i]=gPost("i".$i);
}
$pid = gPost("id");
//echo $pid."<br/>";
$sql = "select post_id from wp_postmeta where meta_key = 'geocraft_googleplus' and meta_value='https://plus.google.com/$pid/posts'";
$result=mysql_query($sql);
$sql = "insert IGNORE into wp_postmeta (post_id,meta_key,meta_value) VALUE ";
$sql.= "('#post_id','geocraft_meta_image1','".$img[1]."')";
for ($i=2; $i<=5; $i++) {
	if ($img[$i])
		$sql.= ",('#post_id','geocraft_meta_image$i','".$img[$i]."')";
}
//echo $sql."<br/>";
while ($data=mysql_fetch_array($result)) {
	$sql2=str_replace("#post_id",$data['post_id'],$sql);
	//echo $sql2."<br/>";
	$ret = mysql_query($sql2);
}
echo "OK";

function gPost($gp)
{
	if (isset($_POST[$gp]))
		return $_POST[$gp];
	else
		return "";
}


function post_meta($post_id,$meta, $txt) {
	$sql="INSERT INTO wp_postmeta (post_id,meta_key,meta_value) VALUES('$post_id','$meta','$txt');";
	$result = mysql_query($sql);
}
?>